home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / adaptor.zip / ADAPT.ZIP / adaptor / dalib / pvm3 / overlap0.c < prev    next >
Text File  |  1993-12-02  |  9KB  |  263 lines

  1. /**************************************************************************
  2. *                                                                         *
  3. *  Author      : Dr. Thomas Brandes, GMD, I1.HR                           *
  4. *  Copyright   : GMD St. Augustin, Germany                                *
  5. *  Date        : Apr 93                                                   *
  6. *  Last Update : Apr 93                                                   *
  7. *                                                                         *
  8. *  This Module is part of the DALIB / UNILIB                              *
  9. *                                                                         *
  10. *  Module      : overlap0.c                                               *
  11. *                                                                         *
  12. *  Function    : fill out overlapping areas (without communication)       *
  13. *                                                                         *
  14. *   source  : is a source array                                           *
  15. *   target  : is the target, conform with source, but has an overlap      *
  16. *                                                                         *
  17. **************************************************************************/
  18.  
  19. # undef DEBUG
  20.  
  21.      /*********************************************************
  22.      *                                                        *
  23.      *  Overlap of one segment (without communication)        *
  24.      *                                                        *
  25.      *   l1      N1                              r1           *
  26.      *  -----------------------------------------------       *
  27.      *  |T    | Sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |     |       *
  28.      *  -----------------------------------------------       *
  29.      *                                                        *
  30.      *  this function works for every size, also for          *
  31.      *  whole rows of two-dimensional arrays , ...            *
  32.      *                                                        *
  33.      *********************************************************/
  34.  
  35. void dalib_local_overlap (target, source, N1, l1, r1)
  36.  
  37. unsigned char *target, *source;
  38. int N1, l1, r1;
  39.  
  40. {  unsigned char *tptr, *sptr;
  41.  
  42. #ifdef DEBUG
  43.    printf ("dalib_local_overlap, N1 = %d, l1 = %d, r1 = %d\n", N1, l1, r1);
  44. #endif
  45.  
  46.   /* copy left overlap area, target (1:l1) = source (N1-l1+1:N1) */
  47.  
  48.   tptr = target;
  49.   sptr = source + N1 - l1;
  50.   dalib_memcpy (tptr, sptr, l1);
  51.  
  52.   /* copy source to target , target (l1:l1+N1) = source(1:N1)
  53.      only necessary if source and target are not the same      */
  54.  
  55.   tptr += l1;
  56.   if (tptr != source)
  57.      dalib_memcpy (tptr, source, N1);
  58.  
  59.   /* copy right overlap area, target (N1+l1+1:N1+l1+r1) = source(1:r1) */
  60.  
  61.   tptr += N1;
  62.   dalib_memcpy (tptr, source, r1);
  63.  
  64. #ifdef DEBUG
  65.    printf ("dalib_local_overlap ready\n");
  66. #endif
  67.  
  68. }  /* dalib_local_overlap */
  69.  
  70.      /*********************************************************
  71.      *                                                        *
  72.      *  Overlapping of two-dimensional segments               *
  73.      *                                                        *
  74.      *      l2      N2                              r2        *
  75.      *     -----------------------------------------------    *
  76.      *     |T      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,       |    *
  77.      * l1  |       ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,       |    *
  78.      *     |     | Sxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |     |    *
  79.      * N1  |     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |     |    *
  80.      *     |     | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |     |    *
  81.      *     |       ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,       |    *
  82.      * r1  |       ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,       |    *
  83.      *     -----------------------------------------------    *
  84.      *                                                        *
  85.      *********************************************************/
  86.  
  87. void dalib_overlap_seg2 (last_dim_flag, target, source, N1, l1, r1, N2, l2, r2)
  88.  
  89. int last_dim_flag;
  90. unsigned char *target, *source;
  91. int N1, l1, r1, N2, l2, r2;
  92.  
  93. { int step, i;
  94.   unsigned char *tptr, *sptr;
  95.  
  96. #ifdef DEBUG
  97.    printf ("dalib_overlap_seg2\n");
  98.    printf ("N1 = %d, l1 = %d, r1 = %d\n", N1, l1, r1);
  99.    printf ("N2 = %d, l2 = %d, r2 = %d\n", N2, l2, r2);
  100. #endif
  101.  
  102.   step = N1 + l1 + r1;
  103.  
  104.   /* step 1 : overlap in the rows, that is area with ,,,,,  */
  105.  
  106.   tptr = target + l2 * step;
  107.   sptr = source;
  108.  
  109.   for (i=0; i<N2; i++)
  110.    { dalib_local_overlap (tptr, sptr, N1, l1, r1);
  111.      tptr += step;
  112.      sptr += N1;
  113.    }
  114.  
  115.   /* step 2 : overlap in the last dimension */
  116.  
  117.   if (last_dim_flag)
  118.      dalib_local_overlap (target, target + l2 * step,
  119.                           N2 * step, l2 * step, r2 * step);
  120.  
  121. }  /* dalib_overlap_seg2 */
  122.  
  123.      /*********************************************************
  124.      *                                                        *
  125.      *  Overlapping of three-dimensional segments             *
  126.      *                                                        *
  127.      *********************************************************/
  128.  
  129. void dalib_overlap_seg3 (last_dim_flag, target, source,
  130.                          N1, l1, r1, N2, l2, r2, N3, l3, r3)
  131.  
  132. int last_dim_flag;
  133. unsigned char *target, *source;
  134. int N1, l1, r1, N2, l2, r2, N3, l3, r3;
  135.  
  136. { int step, i;
  137.   unsigned char *tptr, *sptr;
  138.  
  139. #ifdef DEBUG
  140.    printf ("dalib_overlap_seg3\n");
  141.    printf ("N1 = %d, l1 = %d, r1 = %d\n", N1, l1, r1);
  142.    printf ("N2 = %d, l2 = %d, r2 = %d\n", N2, l2, r2);
  143.    printf ("N3 = %d, l3 = %d, r3 = %d\n", N3, l3, r3);
  144. #endif
  145.  
  146.   step = (N1+l1+r1) * (N2+l2+r2);
  147.  
  148.   /* step 1 : overlap in the first dimensions */
  149.  
  150.   tptr = target + l3 * step;
  151.   sptr = source;
  152.  
  153.   for (i=0; i<N3; i++)
  154.    { dalib_overlap_seg2 (1, tptr, sptr, N1, l1, r1, N2, l2, r2);
  155.      tptr += step;
  156.      sptr += N1*N2;
  157.    }
  158.  
  159.   /* step 2 : overlap in the last dimension */
  160.  
  161.   if (last_dim_flag)
  162.        dalib_local_overlap (target, target + l3 * step,
  163.                               N3 * step, l3 * step, r3 * step);
  164.  
  165. }  /* dalib_overlap_seg3 */
  166.  
  167.      /*********************************************************
  168.      *                                                        *
  169.      *  Overlapping of four-dimensional segments              *
  170.      *                                                        *
  171.      *********************************************************/
  172.  
  173. void dalib_overlap_seg4 (last_dim_flag, target, source,
  174.                          N1, l1, r1, N2, l2, r2,
  175.                          N3, l3, r3, N4, l4, r4)
  176.  
  177. int last_dim_flag;
  178. unsigned char *target, *source;
  179. int N1, l1, r1, N2, l2, r2, N3, l3, r3, N4, l4, r4;
  180.  
  181. { int step, i;
  182.   unsigned char *tptr, *sptr;
  183.  
  184.   step = (N1+l1+r1) * (N2+l2+r2) * (N3+l3+r3);
  185.  
  186.   /* step 1 : overlap in the first dimensions */
  187.  
  188.   tptr = target + l4 * step;
  189.   sptr = source;
  190.  
  191.   for (i=0; i<N4; i++)
  192.    { dalib_overlap_seg3 (1, tptr, sptr, N1, l1, r1, N2, l2, r2, N3, l3, r3);
  193.      tptr += step;
  194.      sptr += N1*N2*N3;
  195.    }
  196.  
  197.   /* step 2 : overlap in the last dimension */
  198.  
  199.   if (last_dim_flag)
  200.      dalib_local_overlap (target, target + l4 * step,
  201.                           N4 * step, l4 * step, r4 * step);
  202.  
  203. }  /* dalib_overlap_seg4 */
  204.  
  205. /**************************************************************************
  206. *                                                                         *
  207. *  Overlapping of replicated arrays or host arrays (no communication)     *
  208. *                                                                         *
  209. **************************************************************************/
  210.  
  211. void dalib_loverlap1__ (target, source, N1, l1, r1, size)
  212.  
  213. unsigned char *target, *source;
  214. int *N1, *l1, *r1, *size;
  215.  
  216. /*   source is (N1), target is (N1+l1+r1), size is number of bytes */
  217.  
  218. { int bytes;
  219.  
  220.   bytes = *size;
  221.   dalib_local_overlap (target, source, *N1*bytes, *l1*bytes, *r1*bytes);
  222.  
  223. }  /* dalib_loverlap1 */
  224.  
  225. void dalib_loverlap2__ (target, source, N1, l1, r1, N2, l2, r2, size)
  226.  
  227. unsigned char *target, *source;
  228. int *N1, *l1, *r1, *N2, *l2, *r2, *size;
  229.  
  230. { int bytes;
  231.  
  232.   bytes = *size;
  233.   dalib_overlap_seg2 (1, target, source, *N1*bytes, *l1*bytes, *r1*bytes,
  234.                                       *N2, *l2, *r2);
  235. } /* dalib_loverlap2_ */
  236.  
  237. void dalib_loverlap3__ (target, source, N1, l1, r1, N2, l2, r2, N3, l3, r3, size)
  238.  
  239. unsigned char *target, *source;
  240. int *N1, *l1, *r1, *N2, *l2, *r2, *N3, *l3, *r3, *size;
  241.  
  242. { int bytes;
  243.  
  244.   bytes = *size;
  245.   dalib_overlap_seg3 (1, target, source, *N1*bytes, *l1*bytes, *r1*bytes,
  246.                                       *N2, *l2, *r2, *N3, *l3, *r3);
  247.  
  248. } /* dalib_loverlap_seg3_ */
  249.  
  250. void dalib_loverlap4__ (target, source, N1, l1, r1, N2, l2, r2,
  251.                                        N3, l3, r3, N4, l4, r4, size)
  252.  
  253. unsigned char *target, *source;
  254. int *N1, *l1, *r1, *N2, *l2, *r2, *N3, *l3, *r3, *N4, *l4, *r4, *size;
  255.  
  256. { int bytes;
  257.  
  258.   bytes = *size;
  259.   dalib_overlap_seg4 (1, target, source, *N1*bytes, *l1*bytes, *r1*bytes,
  260.                       *N2, *l2, *r2, *N3, *l3, *r3, *N4, *l4, *r4);
  261.  
  262. } /* dalib_loverlap4_ */
  263.